function recpos=nberdates_samp(sample) 
% ===============================================================
% function recpos=nberdates_samp(sample) 
%
% Find position in sample vector corresponding to START and END of
% recessions. Currently tabulated recession dates since 1937
% 
% Input 
% ------
% SAMPLE  Vector of quarterly sample dates where 
%        2001Q1=2000.00  
%        2001Q2=2000.25 
%        2001q3=2000.50 
%        2001q4=2000.75
% 
% RECPOS  Matrix [position recession start     posotion recession end]
% Alejandro Justiniano Feb 6th 2009 
% ===================================================================
% Extract the dates of peaks and troughs using NBER procedure  
peaks=[1937.25 
       1945.00 
       1948.75 
       1953.25 
       1957.5
       1960.25 
       1969.75
       1973.75 
       1980.00 
       1981.5
       1990.5
       2001.00 
       2007.75 ];
       
troughs=[1938.25
        1945.75
        1949.75 
        1954.25 
        1958.25 
        1961.00  
        1970.75 
        1975.00 
        1980.5
        1982.75 
        1991.00 
        2001.75 
        2008.75]; 

    if sample(1) < peaks(1); 
        disp('Recession indicator starts 1937...after your sample start') 
    end 
    if sample(end) > peaks(end); 
        disp('Last date of current recession is 2008q4') 
    end 
    
% ====================================================    
% Determine how many recessions are there in the sample     
% Trim to that 
% ======================================================
c1=find( ismember(peaks,sample) == 1); 
c2=find( ismember(troughs,sample) == 1); 
peaks=peaks(c1); 
troughs=troughs(c2); 
if length(peaks)~=length(troughs) 
    peaks=peaks(1:end-1); 
end 
dispaj('First recession starts ',peaks(1),' ends ',troughs(1)); 
dispaj('Last  recession starts ',peaks(end),' ends ',troughs(end)); 
nres=length(peaks); 
recpos=zeros(nres,2); 
for ii=1:nres 
    recpos(ii,1)=find( sample == peaks(ii)); 
    recpos(ii,2)=find( sample == troughs(ii)); 
end 
   